const utils           = require('../../../utils');
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class RequestDemoHandler extends BaseHandler {

    get pattern() {
        return "/request-a-demo";
    }

    doGET(request, response) {
        var security_code = utils.uuid();
        this.ensureRef(request);
        request.session.user.security_code = security_code;
        response.redirect('/signup?ref=request-a-demo');
    }

    doPOST(request, response) {
        this.Controller.saveDemoRequest(request.body, (result) => {
            response.end(JSON.stringify(result));
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = RequestDemoHandler;